import './index.scss'
import {View, WebView} from '@tarojs/components'
import {observer} from 'mobx-react'
import {useContext, useEffect} from 'react'
import Taro, {useDidHide, useDidShow, useRouter} from '@tarojs/taro'
import {webViewStore} from './model'

const Webview = () => {
  let router = useRouter()
  const {pageQuery, updatePageQuery} = useContext(webViewStore)

  // 可以使用所有的 React Hooks
  useEffect(() => {
    console.log('Webview useEffect')
  })
  // 对应 onShow
  useDidShow(() => {
    console.log('Webview useDidShow')
    updatePageQuery(router.params)
    if (pageQuery.title)
      Taro.setNavigationBarTitle({
        title: pageQuery.title
      })
  })
  // 对应 onHide
  useDidHide(() => {
    console.log('Webview useDidHide')
  })
  return <WebView src={pageQuery.url}></WebView>
}
export default observer(Webview)
